// 链表的使用者

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

struct student
{
    int age;
    char name[20];
};

#define DATATYPE struct student
#include "linklist.h"

// 回调函数（钩子函数）
void showInfo(struct student someone)
{
    printf("姓名：%s\t", someone.name);
    printf("年龄：%d\n", someone.age);
}

// 回调函数（钩子函数）
void assign(struct student *s1, struct student s2)
{
    *s1 = s2;
}

// 回调函数，用来比对两个student是否一样
bool equal(struct student s1, struct student s2)
{
    return (s1.age == s2.age && !strcmp(s1.name, s2.name));
}

int main(int argc, char const *argv[])
{
    struct node *head = init_list();

    struct student Jack = {21, "Jack"};
    struct student Rose = {12, "Rose"};
    struct student Mike = {21, "Mike"};

    add_list(head, new_node(Jack, assign));
    add_list(head, new_node(Rose, assign));

    list_for_each(head, showInfo);

    // 在链表中查找数据Jack，提供比对函数equal
    if(find(head, Jack, equal))
        printf("找到了: %s\n", Jack.name);

    return 0;
}
